package com.block.datapush.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.block.datapush.service.IMemberPushOrderInfoService;
import com.block.datapush.special.enums.OrderStatusEnum;
import com.block.db.entity.MemberExtInfo;
import com.block.db.entity.MemberPushOrderInfo;
import com.block.db.entity.SpecialCostomInfo;
import com.block.db.entity.SpecialCostomItemInfo;
import com.block.db.mapper.MemberPushOrderInfoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * <p>
 * 用户推送订单 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-07-08
 */
@Service
public class MemberPushOrderInfoServiceImpl extends ServiceImpl<MemberPushOrderInfoMapper, MemberPushOrderInfo> implements IMemberPushOrderInfoService {

    @Resource
    MemberPushOrderInfoMapper memberPushOrderInfoMapper;

    @Override
    public MemberPushOrderInfo selectMemberPushOrderInfoByPushId(String pushId) {
        MemberPushOrderInfo entityByPushId = memberPushOrderInfoMapper.getEntityByPushId(pushId);
        return entityByPushId;
    }

    @Override
    public MemberPushOrderInfo savePushOrderInfo(SpecialCostomItemInfo itemInfo, SpecialCostomInfo costomInfo, MemberExtInfo memberExtInfo){

        // 保存推送订单信息
        MemberPushOrderInfo pushOrderInfo = new MemberPushOrderInfo();
        pushOrderInfo.setDateInfo(LocalDate.now().toString());
        pushOrderInfo.setInfoId(itemInfo.getInfoId());
        pushOrderInfo.setInfoType(itemInfo.getInfoType());
        pushOrderInfo.setInfoName(costomInfo.getName());
        pushOrderInfo.setUid(memberExtInfo.getUid());
        pushOrderInfo.setTaskId(itemInfo.getId());
        pushOrderInfo.setPriceAmount(itemInfo.getPriceAmount());
        pushOrderInfo.setStatus(OrderStatusEnum.INIT.getValue());
        if (ObjectUtil.isNotEmpty(costomInfo.getDeptId())){
            pushOrderInfo.setDeptId(Long.valueOf(costomInfo.getDeptId()));
        }
        this.save(pushOrderInfo);

        return this.getById(pushOrderInfo.getId());
    }
}
